package com.iplant.ams.service.po.dms;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.iplant.ams.service.po.ams.asset.AMSAssetInfo;
import com.iplant.base.po.BasePO;
import com.iplant.base.po.enums.DBSchemas;
import com.iplant.base.utils.annotation.field.DBField;
import com.iplant.base.utils.annotation.condition.DBCondition;
import com.iplant.base.utils.annotation.join.DBJoin;
import com.iplant.base.utils.annotation.join.multi.DBJoinMulti;
import com.iplant.base.utils.annotation.po.DBBasePO;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@DBBasePO(TableName = "dms_device_ledger", Name = false, Code = false, Active = false,
        Schemas = DBSchemas.AMS, CheckName = {"AssetInfoID"},Cache = true)
public class DMSDeviceLedger extends BasePO implements Serializable {
    private static final long serialVersionUID = 1L;

    @DBCondition
    @DBField
    public int AssetInfoID = 0;
    @DBCondition
    @DBField
    public int ModelID = 0;


    @DBCondition
    @DBJoin(name = "DeviceTypeID", tableName = "dms_device_model", tableAsName = "d1", Schemas = DBSchemas.AMS,
            MainTableField
                    = "ModelID")
    public int DeviceTypeID = 0;

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "dms_device_type", tableAsName = "d2", JoinIndex = 2, Schemas = DBSchemas.AMS,
            ConditionalJoin = "d1.DeviceTypeID=d2.ID")
    public String DeviceTypeName = "";


    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Code", tableName = "dms_device_type", tableAsName = "d2", JoinIndex = 2, Schemas = DBSchemas.AMS,
            ConditionalJoin = "d1.DeviceTypeID=d2.ID")
    public String DeviceTypeCode = "";


    /**
     * 采集编号
     **/
    @DBCondition
    @DBField
    public String AssetNo = "";

    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "ams_asset_list", tableAsName = "a1", Schemas = DBSchemas.AMS,
            MainTableField
                    = "AssetInfoID")
    public String Name = "";
    @DBCondition(ParamName = "Code", CompareType = DBCondition.DBCompareType.like, ParamName2 = "CodeEQ")
    @DBJoin(name = "Code", tableName = "ams_asset_list", tableAsName = "a1", Schemas = DBSchemas.AMS,
            MainTableField
                    = "AssetInfoID")
    public String Code = "";

    @DBCondition
    @DBJoin(name = "Active", tableName = "ams_asset_list", tableAsName = "a1", Schemas = DBSchemas.AMS,
            MainTableField
                    = "AssetInfoID")
    public int Active = 0;


    /**
     * 标准型号ID
     */
    @DBCondition
    @DBJoin(name = "StandardModelID", tableName = "ams_asset_list", tableAsName = "a1", Schemas = DBSchemas.AMS,
            MainTableField
                    = "AssetInfoID")
    public int StandardModelID = 0;

    /**
     * 标准型号名称
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "ams_asset_standard_model", tableAsName = "a2", JoinIndex = 2, Schemas =
            DBSchemas.AMS,
            ConditionalJoin = "a1.StandardModelID=a2.ID")
    public String StandardModelName = "";

    /**
     * 标准型号编码
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Code", tableName = "ams_asset_standard_model", tableAsName = "a2", JoinIndex = 2, Schemas =
            DBSchemas.AMS,
            ConditionalJoin = "a1.StandardModelID=a2.ID")
    public String StandardModelCode = "";

    /**
     * 资产型号
     */
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "AssetModel", tableName = "ams_asset_standard_model", tableAsName = "a2", Schemas = DBSchemas.AMS,
            ConditionalJoin = "a1.StandardModelID=a2.ID")
    public String AssetModel = "";


    /**
     * 厂家名称
     **/

    @DBField
    public String ManufactorName = "";
    /**
     * 出厂编号
     **/
    @DBField
    public String ManufactorCode = "";
    /**
     * 厂家联系方式
     **/
    @DBField
    public String ManufactorContactInfo = "";

    @DBJoin(name = "SupplierID", tableName = "ams_asset_list", tableAsName = "a1", Schemas = DBSchemas.AMS,
            MainTableField
                    = "AssetInfoID")
    public int SupplierID = 0;

    @DBJoin(name = "Name", tableName = "crm_customer", tableAsName = "c1", JoinIndex = 2, Schemas = DBSchemas.Basic,
            ConditionalJoin = "a1.SupplierID=c1.ID")
    public String SupplierName = "";

    @DBJoin(name = "Code", tableName = "crm_customer", tableAsName = "c1", JoinIndex = 2, Schemas = DBSchemas.Basic,
            ConditionalJoin = "a1.SupplierID=c1.ID")
    public String SupplierCode = "";
    /**
     * 供应商联系方式
     **/
    @DBField
    public String SupplierContactInfo = "";

    /**
     * 验收日期
     */
    @DBField
    public Calendar AcceptanceDate = Calendar.getInstance();

    /**
     * 质保期
     **/
    @DBField
    public int WarrantyPeriod = 0;

    /**
     * 承重
     */
    @DBField
    public double Bearing = 0.0;

    /**
     * 最大作业高度
     */
    @DBField
    public double MaxHeight = 0.0;


    @DBField
    public int WorkMode = 0;

    @DBCondition
    @DBField
    public int WorkAreaID = 0;
    @DBCondition(CompareType = DBCondition.DBCompareType.like)
    @DBJoin(name = "Name", tableName = "fmc_workarea", tableAsName = "w2", MainTableField = "WorkAreaID")
    public String WorkAreaName = "";

    @DBJoin(name = "Code", tableName = "fmc_workarea", tableAsName = "w2", MainTableField = "WorkAreaID")
    public String WorkAreaCode = "";


    @DBCondition
    @DBJoin(name = "WorkshopID", tableName = "fmc_workarea", tableAsName = "w2", MainTableField = "WorkAreaID")
    public int WorkshopID = 0;
    @DBJoin(name = "Name", tableName = "fmc_workshop", tableAsName = "w1", JoinIndex = 2, ConditionalJoin = "w2" +
            ".WorkshopID=w1.ID")
    public String WorkshopName = "";
    @DBJoin(name = "Code", tableName = "fmc_workshop", tableAsName = "w1", JoinIndex = 2, ConditionalJoin = "w2" +
            ".WorkshopID=w1.ID")
    public String WorkshopCode = "";

    @DBCondition
    @DBJoin(name = "FactoryID", tableName = "fmc_workshop", tableAsName = "w1", JoinIndex = 2, ConditionalJoin = "w2" +
            ".WorkshopID=w1.ID")
    public int FactoryID = 0;

    @DBJoin(name = "Code", tableName = "fmc_factory", tableAsName = "f1", JoinIndex = 3, ConditionalJoin = {"w1" +
            ".FactoryID=f1.ID"})
    public String FactoryCode = "";


    @DBJoin(name = "Name", tableName = "fmc_factory", tableAsName = "f1", JoinIndex = 3, ConditionalJoin = "w1" +
            ".FactoryID=f1.ID")
    public String FactoryName = "";

    /**
     * 设备IP
     **/
    @DBField
    public String DeviceIP = "";

    /**
     * 维护人员ID
     **/
    @DBField
    public List<Integer> MaintainerID = new ArrayList<Integer>();
    /**
     * 维护人员名称
     **/
    @DBJoinMulti(Name = "Name", TableName = "mbs_user", MainTableField = "MonitorIDs")
    public String MaintainerName = "";
    @DBJoinMulti(Name = "Code", TableName = "mbs_user", MainTableField = "MonitorIDs")
    public String MaintainerCode = "";

    /**
     * 状态采集启用
     **/
    @DBCondition
    @DBField
    public int StatusEnable = 0;

    /**
     * 状态显示采集启用
     */
    @DBCondition
    @DBField
    public int StatusShowEnable = 0;


    /**
     * 报警采集启用
     **/
    @DBField
    public int AlarmEnable = 0;

    /**
     * 参数采集启用
     **/
    @DBField
    public int ParameterEnable = 0;

    /**
     * 工作参数采集启用
     **/
    @DBField
    public int WorkParameterEnable = 0;

    /**
     * 刀具管理启用
     **/
    @DBField
    public int ToolEnable = 0;

    /**
     * 加工程序启用
     **/
    @DBField
    public int NCEnable = 0;


    /**
     * 工装启用
     */
    @DBField
    public int FixturesEnable = 0;

    /**
     * 理论节拍
     */
    @DBField
    public double PartInterval = 35 * 60;

    @DBField
    public String ImageIcon = "";

    /**
     * 设备当前状态（看板用）
     */
    public int DeviceStatus = 0;

    /**
     * 指导文件ID
     */
    @DBField
    public List<Integer> FileIDList = new ArrayList<>();

    /**
     * 指导文件路径
     */
    @DBJoinMulti(Name = "FileUrl", MainTableField = "FileIDList", TableName = "sfc_file", Schemas = DBSchemas.MES
    )
    public String FileUrls = "";

    public DMSDeviceLedger() {
        super();
    }

    public DMSDeviceLedger(AMSAssetInfo wAMSAssetInfo, DMSDeviceModel wDMSDeviceModel) {
        super();


        Code = wAMSAssetInfo.Code;
        Name = wAMSAssetInfo.Name;
        AssetInfoID = wAMSAssetInfo.ID;
        AssetNo = wAMSAssetInfo.AssetSN;
        ModelID = wDMSDeviceModel.ID;
        StandardModelID = wAMSAssetInfo.StandardModelID;
        StandardModelName = wAMSAssetInfo.StandardModelName;
        StandardModelCode = wAMSAssetInfo.StandardModelCode;
        SupplierID = wAMSAssetInfo.SupplierID;
        ImageIcon = wAMSAssetInfo.AssetImage;
        DeviceTypeID = wDMSDeviceModel.DeviceTypeID;
        DeviceTypeName = wDMSDeviceModel.DeviceTypeName;
        DeviceTypeCode = wDMSDeviceModel.DeviceTypeCode;
        Active = wAMSAssetInfo.Active;
    }

    public String ChangeToTableName() {

        Matcher wMatcher = Pattern.compile("(?<Column>[^A-Za-z0-9_])", Pattern.CASE_INSENSITIVE).matcher(
                Code);

        return wMatcher.replaceAll("_");
    }


    @JsonProperty("AssetInfoID")
    public int getAssetInfoID() {
        return AssetInfoID;
    }

    public void setAssetInfoID(int assetInfoID) {
        AssetInfoID = assetInfoID;
    }

    @JsonProperty("ModelID")
    public int getModelID() {
        return ModelID;
    }

    public void setModelID(int modelID) {
        ModelID = modelID;
    }

    @JsonProperty("DeviceTypeID")
    public int getDeviceTypeID() {
        return DeviceTypeID;
    }

    public void setDeviceTypeID(int deviceTypeID) {
        DeviceTypeID = deviceTypeID;
    }

    @JsonProperty("DeviceTypeName")
    public String getDeviceTypeName() {
        return DeviceTypeName;
    }

    public void setDeviceTypeName(String deviceTypeName) {
        DeviceTypeName = deviceTypeName;
    }

    @JsonProperty("DeviceTypeCode")
    public String getDeviceTypeCode() {
        return DeviceTypeCode;
    }

    public void setDeviceTypeCode(String deviceTypeCode) {
        DeviceTypeCode = deviceTypeCode;
    }

    @JsonProperty("AssetNo")
    public String getAssetNo() {
        return AssetNo;
    }

    public void setAssetNo(String assetNo) {
        AssetNo = assetNo;
    }

    @Override
    @JsonProperty("Name")
    public String getName() {
        return Name;
    }

    @Override
    public void setName(String name) {
        Name = name;
    }

    @Override
    @JsonProperty("Code")
    public String getCode() {
        return Code;
    }

    @Override
    public void setCode(String code) {
        Code = code;
    }

    @Override
    @JsonProperty("Active")
    public int getActive() {
        return Active;
    }

    @Override
    public void setActive(int active) {
        Active = active;
    }

    @JsonProperty("StandardModelID")
    public int getStandardModelID() {
        return StandardModelID;
    }

    public void setStandardModelID(int standardModelID) {
        StandardModelID = standardModelID;
    }

    @JsonProperty("StandardModelName")
    public String getStandardModelName() {
        return StandardModelName;
    }

    public void setStandardModelName(String standardModelName) {
        StandardModelName = standardModelName;
    }

    @JsonProperty("StandardModelCode")
    public String getStandardModelCode() {
        return StandardModelCode;
    }

    public void setStandardModelCode(String standardModelCode) {
        StandardModelCode = standardModelCode;
    }

    @JsonProperty("AssetModel")
    public String getAssetModel() {
        return AssetModel;
    }

    public void setAssetModel(String assetModel) {
        AssetModel = assetModel;
    }

    @JsonProperty("ManufactorName")
    public String getManufactorName() {
        return ManufactorName;
    }

    public void setManufactorName(String manufactorName) {
        ManufactorName = manufactorName;
    }

    @JsonProperty("ManufactorCode")
    public String getManufactorCode() {
        return ManufactorCode;
    }

    public void setManufactorCode(String manufactorCode) {
        ManufactorCode = manufactorCode;
    }

    @JsonProperty("ManufactorContactInfo")
    public String getManufactorContactInfo() {
        return ManufactorContactInfo;
    }

    public void setManufactorContactInfo(String manufactorContactInfo) {
        ManufactorContactInfo = manufactorContactInfo;
    }

    @JsonProperty("SupplierID")
    public int getSupplierID() {
        return SupplierID;
    }

    public void setSupplierID(int supplierID) {
        SupplierID = supplierID;
    }

    @JsonProperty("SupplierName")
    public String getSupplierName() {
        return SupplierName;
    }

    public void setSupplierName(String supplierName) {
        SupplierName = supplierName;
    }

    @JsonProperty("SupplierCode")
    public String getSupplierCode() {
        return SupplierCode;
    }

    public void setSupplierCode(String supplierCode) {
        SupplierCode = supplierCode;
    }

    @JsonProperty("SupplierContactInfo")
    public String getSupplierContactInfo() {
        return SupplierContactInfo;
    }

    public void setSupplierContactInfo(String supplierContactInfo) {
        SupplierContactInfo = supplierContactInfo;
    }

    @JsonProperty("AcceptanceDate")
    public Calendar getAcceptanceDate() {
        return AcceptanceDate;
    }

    public void setAcceptanceDate(Calendar acceptanceDate) {
        AcceptanceDate = acceptanceDate;
    }

    @JsonProperty("WarrantyPeriod")
    public int getWarrantyPeriod() {
        return WarrantyPeriod;
    }

    public void setWarrantyPeriod(int warrantyPeriod) {
        WarrantyPeriod = warrantyPeriod;
    }

    @JsonProperty("Bearing")
    public double getBearing() {
        return Bearing;
    }

    public void setBearing(double bearing) {
        Bearing = bearing;
    }

    @JsonProperty("MaxHeight")
    public double getMaxHeight() {
        return MaxHeight;
    }

    public void setMaxHeight(double maxHeight) {
        MaxHeight = maxHeight;
    }

    @JsonProperty("WorkMode")
    public int getWorkMode() {
        return WorkMode;
    }

    public void setWorkMode(int workMode) {
        WorkMode = workMode;
    }

    @JsonProperty("WorkAreaID")
    public int getWorkAreaID() {
        return WorkAreaID;
    }

    public void setWorkAreaID(int workAreaID) {
        WorkAreaID = workAreaID;
    }

    @JsonProperty("WorkAreaName")
    public String getWorkAreaName() {
        return WorkAreaName;
    }

    public void setWorkAreaName(String workAreaName) {
        WorkAreaName = workAreaName;
    }

    @JsonProperty("WorkAreaCode")
    public String getWorkAreaCode() {
        return WorkAreaCode;
    }

    public void setWorkAreaCode(String workAreaCode) {
        WorkAreaCode = workAreaCode;
    }

    @JsonProperty("WorkshopID")
    public int getWorkshopID() {
        return WorkshopID;
    }

    public void setWorkshopID(int workshopID) {
        WorkshopID = workshopID;
    }

    @JsonProperty("WorkshopName")
    public String getWorkshopName() {
        return WorkshopName;
    }

    public void setWorkshopName(String workshopName) {
        WorkshopName = workshopName;
    }

    @JsonProperty("WorkshopCode")
    public String getWorkshopCode() {
        return WorkshopCode;
    }

    public void setWorkshopCode(String workshopCode) {
        WorkshopCode = workshopCode;
    }

    @JsonProperty("FactoryID")
    public int getFactoryID() {
        return FactoryID;
    }

    public void setFactoryID(int factoryID) {
        FactoryID = factoryID;
    }

    @JsonProperty("FactoryCode")
    public String getFactoryCode() {
        return FactoryCode;
    }

    public void setFactoryCode(String factoryCode) {
        FactoryCode = factoryCode;
    }

    @JsonProperty("FactoryName")
    public String getFactoryName() {
        return FactoryName;
    }

    public void setFactoryName(String factoryName) {
        FactoryName = factoryName;
    }

    @JsonProperty("DeviceIP")
    public String getDeviceIP() {
        return DeviceIP;
    }

    public void setDeviceIP(String deviceIP) {
        DeviceIP = deviceIP;
    }

    @JsonProperty("MaintainerID")
    public List<Integer> getMaintainerID() {
        return MaintainerID;
    }

    public void setMaintainerID(List<Integer> maintainerID) {
        MaintainerID = maintainerID;
    }

    @JsonProperty("MaintainerName")
    public String getMaintainerName() {
        return MaintainerName;
    }

    public void setMaintainerName(String maintainerName) {
        MaintainerName = maintainerName;
    }

    @JsonProperty("MaintainerCode")
    public String getMaintainerCode() {
        return MaintainerCode;
    }

    public void setMaintainerCode(String maintainerCode) {
        MaintainerCode = maintainerCode;
    }

    @JsonProperty("StatusEnable")
    public int getStatusEnable() {
        return StatusEnable;
    }

    public void setStatusEnable(int statusEnable) {
        StatusEnable = statusEnable;
    }

    @JsonProperty("AlarmEnable")
    public int getAlarmEnable() {
        return AlarmEnable;
    }

    public void setAlarmEnable(int alarmEnable) {
        AlarmEnable = alarmEnable;
    }

    @JsonProperty("ParameterEnable")
    public int getParameterEnable() {
        return ParameterEnable;
    }

    public void setParameterEnable(int parameterEnable) {
        ParameterEnable = parameterEnable;
    }

    @JsonProperty("WorkParameterEnable")
    public int getWorkParameterEnable() {
        return WorkParameterEnable;
    }

    public void setWorkParameterEnable(int workParameterEnable) {
        WorkParameterEnable = workParameterEnable;
    }

    @JsonProperty("ToolEnable")
    public int getToolEnable() {
        return ToolEnable;
    }

    public void setToolEnable(int toolEnable) {
        ToolEnable = toolEnable;
    }

    @JsonProperty("NCEnable")
    public int getNCEnable() {
        return NCEnable;
    }

    public void setNCEnable(int NCEnable) {
        this.NCEnable = NCEnable;
    }

    @JsonProperty("ImageIcon")
    public String getImageIcon() {
        return ImageIcon;
    }

    public void setImageIcon(String imageIcon) {
        ImageIcon = imageIcon;
    }

    @JsonProperty("StatusShowEnable")
    public int getStatusShowEnable() {
        return StatusShowEnable;
    }

    public void setStatusShowEnable(int statusShowEnable) {
        StatusShowEnable = statusShowEnable;
    }

    @JsonProperty("FixturesEnable")
    public int getFixturesEnable() {
        return FixturesEnable;
    }

    public void setFixturesEnable(int fixturesEnable) {
        FixturesEnable = fixturesEnable;
    }

    @JsonProperty("PartInterval")
    public double getPartInterval() {
        return PartInterval;
    }

    public void setPartInterval(double partInterval) {
        PartInterval = partInterval;
    }

    @JsonProperty("DeviceStatus")
    public int getDeviceStatus() {
        return DeviceStatus;
    }

    public void setDeviceStatus(int deviceStatus) {
        DeviceStatus = deviceStatus;
    }

    @JsonProperty("FileIDList")
    public List<Integer> getFileIDList() {
        return FileIDList;
    }

    public void setFileIDList(List<Integer> fileIDList) {
        FileIDList = fileIDList;
    }

    @JsonProperty("FileUrls")
    public String getFileUrls() {
        return FileUrls;
    }

    public void setFileUrls(String fileUrls) {
        FileUrls = fileUrls;
    }
}
